import loading from "/js/loading.js";
let createCancelDialogWrap = (curriculumid,el) => {
    let div = document.createElement('div')
    div.className = 'cancel-dialog-wrap'
    div.innerHTML = `
        <div class='cancel-dialog-wrap-title'>
            <span>每节课都是通往流利中文的一个台阶</span>
            <i class='iconfont icon-chahao cancel-close'></i>
        </div>
        <div class='cancel-dialog-wrap-title2'>如果不取消的话，你会更快接近目标。如果真的不能上课，请告诉老师原因，并变更时间</div>
        <div class='cancel-dialog-wrap-edit' contenteditable="true">
            <div style='padding:5px'>抱歉，我有一些原因...</div>
        </div>
        <div class='cancel-dialog-wrap-btn'>
            <div class='cancel-dialog-wrap-btn-cancel'>取消</div>
            <div class='cancel-dialog-wrap-btn-change'>变更</div>
        </div>
    `
    document.body.appendChild(div)

    $('.cancel-close')[0].addEventListener('click',() => {
        $('#mask').hide()
        $('#mask')[0].style.zIndex = '-1'
        $('.cancel-dialog-wrap')[0].remove() 
    })

    $('.cancel-dialog-wrap-btn-cancel')[0].addEventListener('click',async () => {
        loading.showLoading({
            type: 2,
            tip: "loading...",
        });

        
        let res = await ajax('refund',{
            curriculumid : curriculumid
        },'post')
        if(res?.code === 200){
            loading.hideLoading();
            Dreamer.success('取消成功')
            el.parents('div.class-block25')[0].remove()
        }else{
            loading.hideLoading();
            Dreamer.success('取消失败')
        }
    })
}

let createRegularCancelDialogWrap = () => {
    let div = document.createElement('div')
    div.className = 'cancel-dialog-wrap-regular'
    div.innerHTML = `
        <div class='cancel-dialog-wrap-title'>
            <span>取消定期预约？</span>
            <i class='iconfont icon-chahao cancel-close'></i>
        </div>
        <div class='cancel-dialog-wrap-title2'>其他学生可能会占用这个时间。</div>
        <div class='cancel-dialog-wrap-btn'>
            <div class='cancel-dialog-wrap-btn-cancel'>取消</div>
            <div class='cancel-dialog-wrap-btn-change'>返回</div>
        </div>
    `

    document.body.appendChild(div)

    $('.cancel-close')[0].addEventListener('click',() => {
        $('#mask').hide()
        $('#mask')[0].style.zIndex = '-1'
        $('.cancel-dialog-wrap-regular')[0].remove() 
    })

    $('.cancel-dialog-wrap-btn-change')[0].addEventListener('click',() => {
        $('#mask').hide()
        $('#mask')[0].style.zIndex = '-1'
        $('.cancel-dialog-wrap-regular')[0].remove() 
    })
}

export {
    createCancelDialogWrap,
    createRegularCancelDialogWrap
}